// OUTDOOR SECTION SCRIPT
//    Section: X = 0, Y = 0: North Ateria

// This is the special encounter script for this town.
// The states INIT_STATE and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

beginoutdoorscript;

variables;

int i,j,k;

body;

beginstate INIT_STATE;
// This state called whenever this section is loaded into memory.
if (get_flag(6,0) != 0) {
	set_terrain(40,30,138);
	set_terrain(41,30,138);
	set_terrain(42,30,137);
	set_terrain(40,31,138);
	set_terrain(41,31,137);
	set_terrain(40,32,156);
	set_terrain(41,32,137);
	}
break;

beginstate START_STATE;
// Starting state of the section, called every turn the party 
// stands inside this section until you change the state.
break;


beginstate 10;
if (get_flag(201,0) == 0) {
	set_flag(201,0,1);
	message_dialog("You leave the woods behind you as you start to climb the mountain. Somewhere farther down this path must be Timoria and the empire deputy.","As you ascend, you notice a few crows circling in the sky above you. Their cries are the only sounds that you hear in the otherwise still quiet.");
	}
break;

beginstate 11;
if (get_flag(201,6) == 0) {
	set_flag(201,6,1);
	message_dialog("From the shadow-infested wood to the craggy mountain you progress, the cold deepening and the total silence growing more deafening by the moment.","");
	place_out_spec_enc(0,41,17);
	}
break;

beginstate 12;
	message_dialog("Suddenly, out of the sky swoop six large bats! They are black, terribly black, and they burn with a feverish, deathly heat. They move towards you as if to rend through your flesh with their hideous teeth.","");
break;

beginstate 13;
if (get_flag(201,1) >= 3)
	end();
	
	block_entry(1);
	reset_dialog();
	add_dialog_str(0,"You come to a cave in the hill. You can hear the sounds of animals inside. Do you investigate?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Investigate.");
	if (run_dialog(1) == 2)
		place_out_spec_enc(get_flag(201,1) + 1,8,36);
break;

beginstate 14;
if (get_flag(201,1) == 0)
	message_dialog("Raveninig and roaring wild bears come tearing at you as you approach the cave mouth, gnashing teeth and claws bared. They attack.","");
if (get_flag(201,1) == 1)
	message_dialog("You move trembling deeper into the cave amidst sounds of dripping and hissing, glittering eyes watching you from the corners of your vision, gone as soon as you look at them. The rocks themselves seem to move.","As you walk forward, you suddenly find yourself surrounded by large bats with gleaming red eyes.");
if (get_flag(201,1) == 2)
	message_dialog("You press on into the cave, quieting your chattering teeth, fighting the unnatural cold, ignoring the burrowing eyes that seek to strip your flesh from your bones to see deeper inside you. As you are walking, suddenly your breath catches.","Before you are two spectral beings. They are the ghosts of the dead which you have been told are always watching but never seen. Now they gaze at you with burning, envious eyes, jealous of your life and wishing to take it from you.");
break;

beginstate 15;
	inc_flag(201,1,1);
	if (get_flag(201,1) == 3)
		message_dialog("You have cleaned out this cave of the source of the monsters. Although the woods will still have dangerous animals, you have gotten rid of the worst of the problem. The locals at Timoria will be very grateful.","You have never before seen the dead walk the land, although you have been warned of their presence. This cannot bode well for Ateria; surely they have offended some powerful god and are suffering his vengeance.");
break;

beginstate 16;
if (get_flag(201,2) == 0) {
	set_flag(201,2,1);
	message_dialog("The woods behind Timoria groan and shriek as the winds of this mountain blow through them. The trees bend and twist as if wrenched by some unseen hand from the sky, tearing their bark and ripping off their branches.","The winds howl malevolently, warning you stay away.");
	}
break;

beginstate 17;
if (get_flag(2,1) == 0) {
	block_entry(1);
	message_dialog("You begin to ascend the mountain, but you remember that you're supposed to talk to the empire's deputy in Timoria to the south before you do anything else.","You turn back.");
	end();
	}
	
if (get_flag(201,3) == 0) {
	set_flag(201,3,1);
	message_dialog("As you begin to ascend the mountain to the castle on the top, you feel the wind start to pick up again. A chill comes over you, and you wait for a moment as it passes.","You can still hear the howls of wolves.");
	}
break;

beginstate 18;
if (get_flag(201,4) == 0) {
	set_flag(201,4,1);
	message_dialog("As you ascend to this final peak, you catch sight of Castle Puteum. It looms above you, a monstrosity towering into the sky as if to split it open and make the gods fall down to earth.","At the top of the tower in the middle of the castle, you see a light in the window and a shadow in the shape of a man blocking some of that light. When he sees that you see him, he disappears.");
	}
break;

beginstate 19;
if (get_flag(201,5) == 0) {
	set_flag(201,5,1);
	message_dialog("When you approach, the gates open, as if of their own free will.","");
	}
break;

beginstate 20;
if (get_flag(6,0) != 0) {
	block_entry(1);
	message_dialog("When you return to Timoria, you find it completely in ruins. Something came through here and destroyed everything.","You don't go inside. There cannot be anything left to find.");
	}
break;

beginstate 21;
if ((get_flag(250,2) == 1) && (get_flag(201,7) == 0)) {
	set_flag(201,7,1);
	message_dialog("As you are walking away from Castle Putideum, you think. Faustulus is dead, so you can't report back to him. You will have to leave Ateria and report back to the governor directly in order to finish your mission.","");
	}
break;